#include "JWorkingCopiesBaseFile.h"
#include "JWorkingCopiesFile.h"


JWorkingCopiesBaseFile::JWorkingCopiesBaseFile(JWorkingCopiesFileOperation _operate,int _lastChangeVersion,
                int _version,std::string _author,std::string _fullFileName,std::string _dirOrFile)
                : operate(_operate),lastChangeVersion(_lastChangeVersion),version(_version),
        author(_author),fullFileName(_fullFileName),dirOrFile(_dirOrFile)
{
	 
}

JWorkingCopiesBaseFile::JWorkingCopiesBaseFile()
{
    
}

JWorkingCopiesBaseFile::~JWorkingCopiesBaseFile(void)
{
}

int JWorkingCopiesBaseFile::Serialize( JInOutPut& _strea ,int& allSize) 
{
    //JWorkingCopiesFileOperation operate;
    //int lastChangeVersion;
    //int version;
    //std::string author;
    //std::string fullFileName;
    //int dirOrFile;
    int classSize = 0, selfSize = 0;
    JSerialize::SerializeHead(_strea, selfSize, classSize);
    JSerialize::Serialize(_strea, this->operate, classSize);
    JSerialize::Serialize(_strea, this->lastChangeVersion, classSize);
    JSerialize::Serialize(_strea, this->version, classSize);
    JSerialize::Serialize(_strea, this->author, classSize);
    JSerialize::Serialize(_strea, this->fullFileName, classSize);
    JSerialize::Serialize(_strea, this->dirOrFile, classSize);
    return JSerialize::SerializeTail(_strea, allSize, selfSize, classSize);
}

int JWorkingCopiesBaseFile::ReSerialize(JInOutPut& _strea) 
{
    int classSize = JSerialize::ReSerializeHead(_strea);
    this->operate = JWorkingCopiesFileOperation(JSerialize::ReSerializeInt(_strea));
    this->lastChangeVersion = JSerialize::ReSerializeInt(_strea);
    this->version = JSerialize::ReSerializeInt(_strea);
    this->author = JSerialize::ReSerializeString(_strea);
    this->fullFileName = JSerialize::ReSerializeString(_strea);
    this->dirOrFile = JSerialize::ReSerializeString(_strea);
    return classSize;
}

/*到远程服务器，建包*/
int JWorkingCopiesBaseFile::PackStubMessage(JInOutPut& _strea, int& _allSize) 
{
    int classSize = 0, selfSize = 0;
    JSerialize::SerializeHead(_strea, selfSize, classSize);
    JSerialize::Serialize(_strea, this->operate, classSize);
    JSerialize::Serialize(_strea, this->fullFileName, classSize);
    JSerialize::Serialize(_strea, this->dirOrFile, classSize);
    return JSerialize::SerializeTail(_strea, _allSize, selfSize, classSize);
}

/*服务器解包*/
int JWorkingCopiesBaseFile::UnPackStubMessage(JInOutPut& _strea) 
{
    int classSize = JSerialize::ReSerializeHead(_strea);
    this->operate = JWorkingCopiesFileOperation(JSerialize::ReSerializeInt(_strea));
    this->fullFileName = JSerialize::ReSerializeString(_strea);
    this->dirOrFile = JSerialize::ReSerializeString(_strea);
    return classSize;
}

//int JWorkingCopiesBaseFile::EnumtoInt( JWorkingCopiesFileOperation _operate )
//{
//	switch(_operate)
//	{
//	case JWorkingFileAdd:
//		return 0;
//	case JWorkingFileDelete:
//		return 1;
//	default:
//		return 2;
//	}
//}

bool JWorkingCopiesBaseFile::operator==( const JWorkingCopiesBaseFile& _file )
{
	if(this->fullFileName == _file.fullFileName)
	{
		return true;
	}
	return false;
}

bool JWorkingCopiesBaseFile::operator < (const JWorkingCopiesBaseFile& _file)
{
    if(this->fullFileName < _file.fullFileName)
    {
        return true;
    }
    return false;
}
std::string JWorkingCopiesBaseFile::FileOperationToString( JWorkingCopiesFileOperation operation )
{
	switch(operation)
	{
	case JWorkingFileAdd:
		return "Add";
	case JWorkingFileDelete:
		return "Delete";
	case JWorkingFileNoStatus:
		return "NoStatus";
	case JWorkingFileNotExist:
		return "NotExist";
	default:
		return "Unknow";
	}
}
